package com.xujl.mvcbind.ui.permission.control;

import android.Manifest;
import android.os.Bundle;
import android.view.View;

import com.tbruyelle.rxpermissions2.RxPermissions;
import com.xujl.fastlib.base.BaseFragment;
import com.xujl.fastlib.utils.ToastUtils;
import com.xujl.mvcbind.ui.permission.model.PermissionRequestFragmentModel;
import com.xujl.mvcbind.ui.permission.view.PermissionRequestFragmentView;

/**
 * <pre>
 *     author : xujl
 *     e-mail : 597355068@qq.com
 *     time   : 2019/08/20
 *     desc   :
 *     version: 1.0
 * </pre>
 */

public class PermissionRequestFragmentControl extends BaseFragment<PermissionRequestFragmentModel, PermissionRequestFragmentView> {

    public static PermissionRequestFragmentControl newInstance () {
        Bundle args = new Bundle();
        PermissionRequestFragmentControl fragment = new PermissionRequestFragmentControl();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void init (Bundle savedInstanceState) {

    }

    @Override
    public void onClick (View view) {
        super.onClick(view);
        request(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE);
    }

    private void request (String... permissions) {
        RxPermissions rxPermissions = new RxPermissions(this);
        rxPermissions.request(permissions)
                .subscribe(aBoolean -> {
                    if (aBoolean) {
                        ToastUtils.toast("请求权限成功");
                    } else {
                        ToastUtils.toast("请求权限被拒绝");
                    }
                });
    }
}
